package com.example.sxmall.service.impl;

import com.example.sxmall.dao.mapper.ShoesMapper;
import com.example.sxmall.dao.pojo.Shoes;
import com.example.sxmall.service.ShoesService;
import com.example.sxmall.vo.ErrorCode;
import com.example.sxmall.vo.Result;
import com.example.sxmall.vo.params.ComprehensivesearchParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShoesServiceImpl implements ShoesService {
    @Autowired
    private ShoesMapper shoesMapper;

    @Override
    public Result findShoes() {
        List<Shoes> shoesList = shoesMapper.listShoes();
        return Result.buildSuccess(shoesList);
    }

    @Override
    public Result ComSearch(ComprehensivesearchParams comParams) {
        int sbid = comParams.getSbid();
        int sizenum = comParams.getSizenum();
        int tid = comParams.getTid();
        String scolor  = comParams.getScolor();
        List<Shoes> list = shoesMapper.comSearchShoes(sbid, tid, sizenum, scolor);
        if (list.isEmpty()||list.size()==0||list == null){
            return Result.buildError(ErrorCode.NO_FIND_SHOES.getCode(), ErrorCode.NO_FIND_SHOES.getMsg());
        }
        return Result.buildSuccess(list);
    }

    @Override
    public Result newShoes(int limit) {
        List<Shoes> newShoesList = shoesMapper.findNewShoes(limit);
        return Result.buildSuccess(newShoesList);
    }

    @Override
    public Result listBrandShoes(int sbid) {
        List<Shoes> listBrandShoes = shoesMapper.findBrandShoes(sbid);
        return Result.buildSuccess(listBrandShoes);
    }

    @Override
    public Result hotShoes(int limit) {
        List<Shoes> listHotShoes = shoesMapper.listHotShoes(limit);
        return Result.buildSuccess(listHotShoes);
    }

    @Override
    public Result priceCutShoes() {
        List<Shoes> listPriceCutShoes = shoesMapper.listPriceCutShoes();
        return Result.buildSuccess(listPriceCutShoes);
    }

    @Override
    public Result fuzzyFindShoes(String keywrod) {
        List<Shoes> findShoesList = shoesMapper.fuzzyFindShoes(keywrod);
        return Result.buildSuccess(findShoesList);
    }
}
